package com.smart.persistence.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "T_BookHotel")
@NamedQueries({
		@NamedQuery(name = BookHotel.findLastBookHotel, query = "SELECT entity FROM BookHotel entity where entity.id = (SELECT MAX(book.id) FROM BookHotel book where book.hotel.id = ?1) "),
		@NamedQuery(name = BookHotel.findBookHotelByCustomer, query = "SELECT entity FROM BookHotel entity where entity.customer = ?1 ")

})
public class BookHotel {

	public static final String findLastBookHotel = "BookHotel.findLastBookHotel";
	public static final String findBookHotelByCustomer = "BookHotel.findBookHotelByCustomer";

	@Id
	@Column(name = "id_book_hotel")
	@TableGenerator(name = "BOOK_HOTEL_GEN", allocationSize = 1, initialValue = 1, table = "T_ID", pkColumnName = "key", valueColumnName = "valor", pkColumnValue = "ID_BOOK_HOTEL")
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "BOOK_HOTEL_GEN")
	private long id;

	private String customer;

	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "bookHotel")
	private List<BookRoom> booksRoom;

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_hotel", nullable = false)
	private Hotel hotel;

	@OneToOne(fetch = FetchType.LAZY, mappedBy = "bookHotel")
	private Payment payment;
	
	@Temporal(value = TemporalType.DATE)
	private Date checkIn;
	
	
	@Temporal(value = TemporalType.DATE)
	private Date checkOut;
	
	
	/*/# INICIO - EXERC. 2*/
	private Date date;
	
	@Temporal (value= TemporalType.DATE)
	public Date getDate() {
		return date;
	}
	public void setDate(Date date) {
		this.date = date;
	}
	
	// FIM - EXERC. 2 #*/
	


	public long getId() {
		return id;
	}
	

	public void setId(long id) {
		this.id = id;
	}

	public List<BookRoom> getBooksRoom() {
		return booksRoom;
	}

	public void setBooksRoom(List<BookRoom> booksRoom) {
		this.booksRoom = booksRoom;
	}

	public Payment getPayment() {
		return payment;
	}

	public void setPayment(Payment payment) {
		this.payment = payment;
	}

	public Hotel getHotel() {
		return hotel;
	}

	public void setHotel(Hotel hotel) {
		this.hotel = hotel;
	}

	public String getCustomer() {
		return customer;
	}

	public void setCustomer(String customer) {
		this.customer = customer;
	}
	
	

	public Date getCheckIn() {
		return checkIn;
	}

	public void setCheckIn(Date checkIn) {
		this.checkIn = checkIn;
	}

	public Date getCheckOut() {
		return checkOut;
	}

	public void setCheckOut(Date checkOut) {
		this.checkOut = checkOut;
	}

	@Override
	public String toString() {
		return "BookHotel [id=" + id + ", booksRoom=" + booksRoom
				+ ", payment=" + payment + "]";
	}

}
